package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.d_c.model.Order;
import com.zr.d_c.service.SellerOrderService;
import com.zr.d_c.service.UserInfoService;
import com.zr.d_c.serviceimpl.SellerOrderServiceImpl;
import com.zr.d_c.serviceimpl.UserInfoServiceImpl;
import com.zr.d_c.model.User;

import net.sf.json.JSONObject;
/**
 * 商家显示当前订单
 * @author Administrator
 *
 */
public class SellerCurrentOrderController extends HttpServlet{
	SellerOrderService so = new SellerOrderServiceImpl();
	UserInfoService userinfo = new UserInfoServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		JSONObject sorder = new JSONObject();
		PrintWriter pw =resp.getWriter();
		HttpSession session = req.getSession();

		int page = Integer.parseInt(req.getParameter("page"));
		int pageSize = Integer.parseInt(req.getParameter("rows"));
		int start = (page-1)*pageSize;
		User user = (User) session.getAttribute("currentUser");
		int sid = userinfo.getSellerSidByUid(user.getUid());
		String searchname = req.getParameter("searchcname");
		if(searchname!=null){
			sorder = so.getSellerCurrentOrder(start, pageSize, sid,searchname);
		}else{
			sorder = so.getSellerCurrentOrder(start, pageSize, sid);
		}
		pw.write(sorder.toString());
	}
}
